import com.huaweicloud.sdk.iot.device.client.requests.CommandRsp;
import com.huaweicloud.sdk.iot.device.service.AbstractService;
import com.huaweicloud.sdk.iot.device.service.DeviceCommand;
import com.huaweicloud.sdk.iot.device.service.Property;


import java.util.Map;
import java.util.Random;

public class Gg extends AbstractService {

    public void setKg(int kg) {
        this.kg = kg;
    }

    public int getMj() {
        return mj;
    }

    //按照设备模型定义属性，注意属性的name和类型需要和模型一致，writeable表示属性知否可写，name指定属性名
    @Property(name = "mj", writeable = false)                   //面积 可读true不可读false
            int mj = 10000;

    public double getSl() {
        sl = new Random().nextInt(100);//水量
        return sl;
    }

    public void setSl(double sl) {
        this.sl = sl;
    }

    @Property(name = "sl", writeable = true)                    //水量 可读true不可读false
            double sl = 1;

    public int getTime() {
        time = new Random().nextInt(100);
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    @Property(name = "time", writeable = true)                  //灌溉时间 可读true不可读false
            int time = 1;

    public int getKg() {
        kg = new Random().nextInt(2);//水量
        return kg;
    }

    public void iskg(int kg) {

        this.kg = kg;
        if (kg == 0){
            System.out.println("ggkg is closed by app");
        }
    }
    @Property(name = "kg", writeable = true)                    //灌溉开关  可读true不可读false
            int kg = 1;

    //定义命令，注意接口入参和返回值类型是固定的不能修改，否则会出现运行时错误
    @DeviceCommand(name = "switch")
    public CommandRsp alarm(Map<String, Object> paras) {

//        int gg = (int) paras.get("gg");   //灌溉开关
//        int sl = (int) paras.get("sl"); //水量
//        int time = (int) paras.get("time");//灌溉时间
        int switch_kg = (int) paras.get("switch_kg");//灌溉开关
        System.out.println("switch  switch_kg = " + switch_kg);
//        System.out.println("switch  sl = " + sl);
//        System.out.println("switch  time = " + time);
//        System.out.println("switch  gg = " + gg);

        //将log换成System.out.println
        CommandRsp commandRsp = new CommandRsp(0);
        commandRsp.setResponseName("COMMAND_RESPONSE");
        //定制
        return commandRsp;
    }

}